import { Request, Response, NextFunction } from "express";
import { usersTable } from "../../database/users-table";

interface Params {
	username: string;
	password: string;
}
export default async (request: Request, response: Response, next: NextFunction) => {
	try {
		const params = request.body as unknown as Params;
		if (!usersTable.users.some((v) => v.username == params.username)) {
			usersTable.register(params);
			response.statusCode = 200;
			response.json(null);
		} else throw new Error();
	} catch (error) {
		response.statusCode = 400;
		next(error);
	}
};
